-- knightship
-- created by wangy
-- 每损失20%的生命值时属性百分比提升（骑士精神）

return {
    -- 返回的是提升的攻击点数
    apply = function(prop, baseValue)
        return prop[3];
    end,

    trigger = function(who, prop, attack)
        local rate = math.modf(1000 * who:queryAttrib("hp") / who:queryAttrib("max_hp"));

        rate = math.max(0, rate);

        local num = math.floor((1000 - rate) / 200);

        local temp  = ME.user.dbase:queryTemp("knightship", 0);

        -- 损失生命提升攻击，触发特技发动特效
        if num > 0 and "attack" == prop[2] then
            ME.user.dbase:setTemp("knightship", num);
            if num > temp then
                EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
            end
        end

        return math.floor(attack * prop[3] * num / 1000);
    end,

    record = function(target, prop, path)
        return false;
    end
};
